﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CCWin;

namespace DC.Views
{
    public partial class Form_TotalFeeData : Skin_DevExpress
    {
        public Form_TotalFeeData()
        {
            InitializeComponent();
        }
        Utils.Database DB = Utils.Global.GlobalDB;

        private void Form_TotalFeeData_Load(object sender, EventArgs e)
        {
            loadUserlist();
            loadFeeData();
            

        }

        private void loadFeeData()
        {
            
            string sql = string.Format(@"select Fee_ID,Fee_Time,Patient_Name,Fee_Real from Fee,Patient where Patient.Patient_ID = Fee.Patient_ID
            and (Fee_Time BETWEEN CONVERT(datetime,'{0}',120) AND CONVERT(datetime,'{1}',120)) and Fee.User_ID =" + comboBox1.SelectedValue,
                                             dateTimePicker1.Value.ToString("yyyy-MM-dd"), dateTimePicker2.Value.AddDays(1).ToString("yyyy-MM-dd"));
            DataView dv = DB.GetDs(sql).Tables[0].DefaultView;
            listView1.Items.Clear();
            listView1.BeginUpdate();
            for (int i = 0; i < dv.Count; i++)
            {
                ListViewItem item = new ListViewItem();
                item.Tag = dv[i]["Fee_ID"].ToString();
                item.Text = dv[i]["Fee_Time"].ToString();
                item.SubItems.Add(dv[i]["Patient_Name"].ToString());
                item.SubItems.Add(dv[i]["Fee_Real"].ToString());
                listView1.Items.Add(item);
            }
            listView1.Columns[2].Width = 122;
            listView1.EndUpdate();

            label5.Text = listView1.Items.Count.ToString();

            float sum = 0;
            foreach (ListViewItem item in listView1.Items)
            {
                sum += Convert.ToSingle(item.SubItems[2].Text);
            }
            label3.Text = sum.ToString();
        }

        private void loadUserlist()
        {
            //加载User下拉框
            comboBox1.Items.Clear();
            DataView UserList = DB.GetDs("select User_ID,Real_Name from [User]").Tables[0].DefaultView;
            comboBox1.DisplayMember = "Real_Name";
            comboBox1.ValueMember = "User_ID";
            comboBox1.DataSource = UserList;
            comboBox1.SelectedIndex = 0;
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            loadFeeData();
        }

        private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
        {
            loadFeeData();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            loadFeeData();
        }
    }
}
